<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="Jce-Eric&#39;s blog">
  <meta name="keyword" content="hexo-theme, vuejs">
  
    <link rel="shortcut icon" href="/blog/css/images/logo.png">
  
  <title>
    
      前、中、后缀表达式 | Jce Eric
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/blog/css/style.css">
  
    <link rel="stylesheet" href="/blog/css/plugins/gitment.css">
  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
    <script src="/blog/js/qrious.js"></script>
  
  
    <script src="/blog/js/gitment.js"></script>
  
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


</head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/blog/">
      <div class="logo"></div>
      <span>Jce Eric</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/blog/" class="item-link">Home</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/blog/tags/" class="item-link">Tags</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/blog/archives/" class="item-link">Archives</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/blog/project/" class="item-link">Projects</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/blog/about/" class="item-link">About</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/blog/" class="menu-link">Home</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/blog/tags/" class="menu-link">Tags</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/blog/archives/" class="menu-link">Archives</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/blog/project/" class="menu-link">Projects</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/blog/about/" class="menu-link">About</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>前、中、后缀表达式</h2>
  <p class="post-date">2019-10-01</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h2 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h2><p>表达式是一种通用的算术或逻辑公式表示方法。根据运算符和操作数的位置关系，可以分为3种。<br><strong>中缀表达式：运算符是以中缀形式处于操作数的中间。比如：a+b。</strong><br><strong>前缀表达式：运算符是以前缀形式处于操作数的前面。比如：+ab。</strong><br><strong>后缀表达式：运算符是以后缀形式处于操作数的后面。比如：ab+。</strong></p>
<p>注：前缀和后缀表达式中是不需要 <code>（</code>和<code>）</code>来表明优先级的。</p>
<p>中缀表达式是我们日常生活中使用的方法。对我们来说是比较容易理解的，但是对于计算机来说，前缀和后缀表达式才是最容易处理的。</p>
<h2 id="前缀和后缀表达式的求值"><a href="#前缀和后缀表达式的求值" class="headerlink" title="前缀和后缀表达式的求值"></a>前缀和后缀表达式的求值</h2><p>前缀表达式的求值：从右到左扫描表达式，遇到操作数时，直接入栈。遇到运算符时，从栈中弹出两个操作数进行运算，将结果入栈。直至遍历完表达式，栈顶元素即位计算结果。</p>
<p>后缀表达式的求值：从左到右扫描表达式，遇到操作数时，直接入栈。遇到运算符时，从栈中弹出两个操作数进行运算，将结果入栈。直至遍历完表达式，栈顶元素即位计算结果。</p>
<p>中缀表达式的求值相对复杂，需要对优先级进行处理，而前后缀表达式则不用。前后缀表达式消除了括号和优先级。</p>
<p>后缀表达式的求值实现如下，前缀类似，不赘述<br><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/*传入的参数exp中使用空格隔开每个元素。比如：“10 20 +” */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">execute</span><span class="params">(String exp)</span></span>&#123;</span><br><span class="line">    String[] expArr = exp.split(<span class="string">" +"</span>);</span><br><span class="line">    Stack&lt;Integer&gt; stack = <span class="keyword">new</span> Stack&lt;&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; expArr.length; i++)&#123;</span><br><span class="line">        <span class="keyword">if</span>(isOperator(expArr[i]))&#123;</span><br><span class="line">            <span class="comment">/*从栈中弹出两个操作数进行操作*/</span></span><br><span class="line">            <span class="keyword">int</span> b = stack.pop();</span><br><span class="line">            <span class="keyword">int</span> a = stack.pop();</span><br><span class="line">            <span class="keyword">switch</span> (expArr[i]) &#123;</span><br><span class="line">                <span class="keyword">case</span> <span class="string">"+"</span>:</span><br><span class="line">                    stack.push(a+b);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> <span class="string">"-"</span>:</span><br><span class="line">                    stack.push(a-b);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> <span class="string">"*"</span>:</span><br><span class="line">                    stack.push(a*b);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> <span class="string">"/"</span>:</span><br><span class="line">                    stack.push(a/b);</span><br><span class="line">                <span class="keyword">default</span>:</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="comment">/*操作数直接入栈*/</span></span><br><span class="line">            stack.push(Integer.parseInt(expArr[i]));</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> stack.pop();</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*判断是否是运算符*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isOperator</span><span class="params">(String s)</span></span>&#123;</span><br><span class="line">    String operatorString = <span class="string">"+-*/()"</span>;</span><br><span class="line">    <span class="keyword">return</span> operatorString.indexOf(s) != -<span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="中缀表达式转后缀表达式"><a href="#中缀表达式转后缀表达式" class="headerlink" title="中缀表达式转后缀表达式"></a>中缀表达式转后缀表达式</h2><h3 id="手工转化"><a href="#手工转化" class="headerlink" title="手工转化"></a>手工转化</h3><p>1.按照运算符的优先级对所有运算单位加括号。<br>2.将所有运算符移动到对应括号的后面。<br>3.去掉所有的括号，得到后缀表达式。</p>
<p>🌰：<code>a+b*c</code><br>步骤1. 加括号： <code>(a+(b*c))</code><br>步骤2. 移动运算符： <code>(a (b c)*)+</code><br>步骤3. 去掉括号：<code>abc*+</code></p>
<h3 id="代码转化"><a href="#代码转化" class="headerlink" title="代码转化"></a>代码转化</h3><p>创建一个栈，用于存储运算符。栈内遵循从栈底往栈顶运算符优先级逐渐提高。<br>从左到右扫描中缀表达式<br>1.遇到操作数时，直接输出。<br>2.遇到<code>(</code>时，直接入栈。<br>3.遇到<code>)</code>时，执行出栈操作，将出栈的元素输出，直到遇到<code>(</code>为止。（<code>(</code>和<code>)</code>不输出，保证了<code>()</code>内的优先运算）<br>4.遇到其他运算符时，比较该运算符和栈顶元素的优先级，当大于栈顶元素优先级时，直接入栈。否则将栈顶元素出栈并输出直到栈顶元素优先级低于该运算符或栈为空为止。（保证了优先级高的运算符优先输出，从左到右扫描后缀表达式时能优先执行）<br>5.将栈中的剩余元素依次出栈输出。<br><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/*设置运算符优先级*/</span></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> Map&lt;String,Integer&gt; priorityMap = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line"><span class="keyword">static</span>&#123;</span><br><span class="line">    priorityMap.put(<span class="string">"("</span>, <span class="number">1</span>);</span><br><span class="line">    priorityMap.put(<span class="string">")"</span>, <span class="number">1</span>);</span><br><span class="line">    priorityMap.put(<span class="string">"+"</span>, <span class="number">2</span>);</span><br><span class="line">    priorityMap.put(<span class="string">"-"</span>, <span class="number">2</span>);</span><br><span class="line">    priorityMap.put(<span class="string">"*"</span>, <span class="number">3</span>);</span><br><span class="line">    priorityMap.put(<span class="string">"/"</span>, <span class="number">3</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*判断是否是运算符*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isOperator</span><span class="params">(String s)</span></span>&#123;</span><br><span class="line">    String operatorString = <span class="string">"+-*/()"</span>;</span><br><span class="line">    <span class="keyword">return</span> operatorString.indexOf(s) != -<span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*传入的参数exp中使用空格隔开每个元素。比如，“10 + 20” */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">inToPos</span><span class="params">(String exp)</span></span>&#123;</span><br><span class="line">    String[] expArr = exp.split(<span class="string">" +"</span>);</span><br><span class="line">    <span class="comment">/*存放结果*/</span></span><br><span class="line">    StringBuilder result = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">    Stack&lt;String&gt; stack = <span class="keyword">new</span> Stack&lt;&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; expArr.length; i++)&#123;</span><br><span class="line">        <span class="keyword">if</span>(isOperator(expArr[i]))&#123;</span><br><span class="line">            <span class="comment">/*当遇到“(”时，直接入栈*/</span></span><br><span class="line">            <span class="keyword">if</span>(expArr[i].equals(<span class="string">"("</span>))&#123;</span><br><span class="line">                stack.push(expArr[i]);</span><br><span class="line">            <span class="comment">/*当遇到“)”时，执行出栈操作，将出栈的元素输出，直到遇到“(”为止*/</span></span><br><span class="line">            &#125;<span class="keyword">else</span> <span class="keyword">if</span> (expArr[i].equals(<span class="string">")"</span>)) &#123;</span><br><span class="line">                <span class="keyword">while</span>(!stack.peek().equals(<span class="string">"("</span>))&#123;</span><br><span class="line">                    result.append(stack.pop());</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">/*弹出"("*/</span></span><br><span class="line">                stack.pop();</span><br><span class="line">            <span class="comment">/*当遇到其他运算符时，对比当前运算符和栈顶运算符的优先级*/</span></span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="keyword">int</span> priority = priorityMap.get(expArr[i]);</span><br><span class="line">                <span class="keyword">while</span>(!stack.isEmpty() &amp;&amp; priority &lt;= priorityMap.get(stack.peek()))&#123;</span><br><span class="line">                    result.append(stack.pop());</span><br><span class="line">                &#125;</span><br><span class="line">                stack.push(expArr[i]);</span><br><span class="line">            &#125;</span><br><span class="line">        <span class="comment">/*遇到操作数时直接输出*/</span></span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            result.append(expArr[i]);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/*将栈中剩余元素出栈输出*/</span></span><br><span class="line">    <span class="keyword">while</span> (!stack.isEmpty()) &#123;</span><br><span class="line">        result.append(stack.pop());</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result.toString();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="中缀表达式转前缀表达式"><a href="#中缀表达式转前缀表达式" class="headerlink" title="中缀表达式转前缀表达式"></a>中缀表达式转前缀表达式</h2><h3 id="手工转化-1"><a href="#手工转化-1" class="headerlink" title="手工转化"></a>手工转化</h3><p>和中缀表达式转后缀表达式类似，不过需要把运算符移动到前面。</p>
<h3 id="代码转化-1"><a href="#代码转化-1" class="headerlink" title="代码转化"></a>代码转化</h3><p>同样和转后缀表达式类似，不过需要从右到左扫描表达式，每次把输出插入到开头。具体代码如下：<br><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">inToPre</span><span class="params">(String exp)</span></span>&#123;</span><br><span class="line">    String[] expArr = exp.split(<span class="string">" +"</span>);</span><br><span class="line">    Stack&lt;String&gt; stack = <span class="keyword">new</span> Stack&lt;&gt;();</span><br><span class="line">    StringBuilder result = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i = expArr.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--)&#123;</span><br><span class="line">        System.out.println(<span class="string">"current:"</span>+expArr[i]);</span><br><span class="line">        <span class="keyword">if</span>(isOperator(expArr[i]))&#123;</span><br><span class="line">            <span class="keyword">if</span>(expArr[i].equals(<span class="string">")"</span>))&#123;</span><br><span class="line">                stack.push(expArr[i]);</span><br><span class="line">            &#125;<span class="keyword">else</span> <span class="keyword">if</span>(expArr[i].equals(<span class="string">"("</span>))&#123;</span><br><span class="line">                <span class="keyword">while</span>(!stack.peek().equals(<span class="string">")"</span>))&#123;</span><br><span class="line">                    result.insert(<span class="number">0</span>, stack.pop());</span><br><span class="line">                &#125;</span><br><span class="line">                stack.pop();</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="keyword">int</span> priority = priorityMap.get(expArr[i]);</span><br><span class="line">                <span class="keyword">while</span> (!stack.isEmpty() &amp;&amp; priority &lt;= priorityMap.get(stack.peek())) &#123;</span><br><span class="line">                    result.insert(<span class="number">0</span>, stack.pop());</span><br><span class="line">                &#125;</span><br><span class="line">                stack.push(expArr[i]);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            result.insert(<span class="number">0</span>, expArr[i]);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">while</span> (!stack.isEmpty()) &#123;</span><br><span class="line">        result.insert(<span class="number">0</span>, stack.pop());</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result.toString();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="构建表达式树"><a href="#构建表达式树" class="headerlink" title="构建表达式树"></a>构建表达式树</h2><p>占个位置，以后再更。</p>
</section>
    <!-- Tags START -->
    
      <div class="tags">
        <span>Tags:</span>
        
  <a href="/blog/blog/tags#数据结构与算法" >
    <span class="tag-code">数据结构与算法</span>
  </a>

      </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/blog/2019/09/19/quickSort/">
        <span class="nav-arrow">← </span>
        
          快速排序
        
      </a>
    
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Gitment START -->
      <div id="comments"></div>
      <!-- Gitment END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#定义"><span class="toc-nav-text">定义</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#前缀和后缀表达式的求值"><span class="toc-nav-text">前缀和后缀表达式的求值</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#中缀表达式转后缀表达式"><span class="toc-nav-text">中缀表达式转后缀表达式</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#手工转化"><span class="toc-nav-text">手工转化</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#代码转化"><span class="toc-nav-text">代码转化</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#中缀表达式转前缀表达式"><span class="toc-nav-text">中缀表达式转前缀表达式</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#手工转化-1"><span class="toc-nav-text">手工转化</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#代码转化-1"><span class="toc-nav-text">代码转化</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#构建表达式树"><span class="toc-nav-text">构建表达式树</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'https://shachunleng.gitee.io/blog/2019/10/01/前中后缀表达式/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>



  <script>
    var gitmentConfig = "Jce-Eric";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "前、中、后缀表达式",
        owner: "Jce-Eric",
        repo: "Jce-Eric.github.io",
        oauth: {
          client_id: "52af927fe48e6c1d9f7e",
          client_secret: "a7dc0d1a1a99003ca896eb1eeb7660967499d91e"
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  </script>




    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2021 | Proudly powered by <a href="https://hexo.io" target="_blank">Hexo</a>
    <br>
    Theme by <a href="https://github.com/yanm1ng">yanm1ng</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'false';
  async("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->

<script src="/blog/js/script.js"></script>
  </body>
</html>